//
// Created by nicemoe on 2021/7/31.
//

#include <iostream>

using namespace std;

void swap(int &, int &);
void swap(int *, int *);
int main() {
    int n, x = 2, decNum = 0, a;
    cout << "请输入要转换的二进制数的位数" << endl;
    cin >> n;
    char *p = new char[n + 1];
    if (p == 0) {
        cout << "申请空间失败" << endl;
        return -1;
    }
    cout << "输入转换的二进制的数" << endl;
    cin >> p;
    for (int i = 0; i < n; ++i) {
        a = p[i] - '0';
        decNum = decNum * x + a;
    }
    cout << "二进制序列（" << p << ")的值为:" << decNum << endl;

    int m = 1, z = 2;
    swap(m, z);
    cout <<"引用方式转换"<< m << " " << z;
    swap(&m, &z);
    cout <<"指针方式转换"<< m << " " << z;
    return 0;
}

void swap(int &x, int &y) {
    int tmp = x;
    x = y;
    y = tmp;
}
void swap(int *x, int *y) {
    int tmp = *x;
    *x = *y;
    *y = tmp;
}